package com.mashibing.controller;

import com.mashibing.internalcommon.dto.DriverUser;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.dto.TokenResult;
import com.mashibing.internalcommon.remote.DriverUserClient;
import com.mashibing.internalcommon.util.JwtUtils;
import com.mashibing.service.DriverUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
public class DriverUserController {
    @Autowired
    private DriverUserClient driverUserClient;

    @Autowired
    private DriverUserService driverUserService;

    @PostMapping("/updateUser")
    public ResponseResult updateUser(@RequestBody DriverUser driverUser) {
        return driverUserClient.updateUser(driverUser);
    }

    /**
     * 根据司机token查询 司机和车辆绑定关系
     * @param request
     * @return
     */
    @GetMapping("/getDriverCarBindingRelationship")
    public ResponseResult getDriverCarBindingRelationship(HttpServletRequest request){

        String authorization = request.getHeader("Authorization");
        TokenResult tokenResult = JwtUtils.checkToken(authorization);
        String driverPhone = tokenResult.getPhone();

        return driverUserService.getDriverCarBindingRelationship(driverPhone);

    }
}
